import * as types from "../types/mineTypes";
import NetWorkUtil from "../utils/NetWorkUtil";
import ApiConstants from "../common/ApiConstants";

export function getUserInfo() {
  return dispatch => {
    NetWorkUtil.post(ApiConstants.USERINFO, {})
      .then(res => {
        dispatch({ type: types.MINE_USERINFO_DONE, userInfo: res });
      })
      .catch(error => {
        dispatch({ type: types.MINE_USERINFO_ERROR, error });
      });
  };
}

export function getStoreLocation(callback) {
  return dispatch => {
    NetWorkUtil.post(ApiConstants.STOREADDRESS, {})
      .then(res => {
        dispatch({ type: types.MINE_STOREINFO_DONE, storeInfo: res });
        callback(res.platform_address);
      })
      .catch(error => {
        dispatch({ type: types.MINE_STOREINFO_ERROR, error });
      });
  };
}

export function logout() {
  return dispatch => {
    dispatch({ type: types.MINE_LOGOUT });
  };
}
